package com.lanou.utp.controller;

import com.lanou.utp.entity.Teacher;
import com.lanou.utp.service.CollegeService;
import com.lanou.utp.service.MajorService;
import com.lanou.utp.service.TeacherEmpService;
import com.lanou.utp.entity.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class TeacherEmpController {

    @Resource
    private TeacherEmpService teacherEmpService;
    @Resource
    private CollegeService collegeService;
    @Resource
    private MajorService majorService;

    /**
     * 刷新页面显示老师信息
     * @param page 页数
     * @return 返回值先确定为Map形式的数据,之后添加工具类写入
     */
    @GetMapping("/school/7/teachers")
    public Map selectTeacherByPage(@RequestParam Integer page){
        return this.teacherEmpService.selectTeacherByPage(page);
    }

    /**
     * 获取学校分院信息
     * @return
     */
//    @GetMapping("/school/7/colleges")
//    public ResponseData selectColleges(){
//        ResponseData responseData = collegeService.selectColleges();
//        return responseData;
//    }

    /**
     * 获取分院专业信息
     * @return
     */
//    @GetMapping("/college/3/majors")
//    public ResponseData selectMajors(){
//        ResponseData responseData = majorService.selectMajors();
//        return responseData;
//    }

//    @GetMapping("/base")
//    public ResponseData selectBase(){
//        teacherEmpService.selectBases();
//        return null;
//    }

    /**
     * 添加一位教师信息
     * @param teacher 教师对象,包含添加的教师信息
     */
    @PostMapping("/teacher")
    public ResponseData addTeacher(@RequestBody Teacher teacher){
        ResponseData responseData = teacherEmpService.addTeacher(teacher);
        //返回成功信息
        return responseData;
    }

    /**
     * 删除单个选中的教师
     * @param id 被选中的教师id集合
     */
    @DeleteMapping("/teacher/{id}")
    public ResponseData deleteTeacher(@PathVariable Integer id){
        ResponseData responseData = teacherEmpService.deleteOneTeacher(id);
        return responseData;
    }

    /**
     * 批量删除教师
     * @param id 被选中的教师id集合
     */
    @DeleteMapping("/teachers/{id}")
    public ResponseData deleteTeachers(@PathVariable List<Integer> id){
        ResponseData responseData = teacherEmpService.deleteSomeTeachers(id);
        return responseData;
    }

    @PutMapping("/teacher/{id}")
    public ResponseData updataTeacher(@PathVariable Integer id,@RequestBody Teacher teacher){
        ResponseData responseData = teacherEmpService.updataTeacher(teacher);
        return responseData;
    }


}
